﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UIWindows.Commands;
using UIWindows.Enums;
using UIWindows.GlobalStatics;
using UIWindows.Models;
using UIWindows.Tools.Helper;
using XingLucifer.IBase;

namespace UIWindows.ViewModels
{
    public class UserManagementViewModel : IViewStatus
    {
        private TemporaryStatic _temporary;
        public UserConfigStatic UserConfig { get; set; }
        public UserManagementViewModel(UserConfigStatic userConfig, TemporaryStatic temporary)
        {
            UserConfig = userConfig;
            _temporary = temporary;
        }

        public DelegateCommand AddUpdate => new DelegateCommand(() => UserConfig.Save());

        public DelegateCommand DeleteData => new DelegateCommand(() => UserConfig.Delect());
        public IEnumerable<AuthorityTypes> Foods
        {
            get
            {
                foreach (AuthorityTypes c in (AuthorityTypes[])Enum.GetValues(typeof(AuthorityTypes)))
                {
                    if ((c != AuthorityTypes.无权限)
                        && (c != AuthorityTypes.ALL)
                        && (c != AuthorityTypes.超级管理员)
                        && !c.ToString().Contains("参照"))
                    {
                        yield return c;
                    }
                }
            }
        }

        /// <summary>
        /// 双击事件
        /// </summary>
        public DelegateCommand<UserModel> MouseDoubleClick => new DelegateCommand<UserModel>(sender => sender?.UpdateValue(UserConfig.User));

        public void Load()
        {
            UserConfig.IsInput = true;
        }

        public void UnLoad()
        {
            UserConfig.IsInput = false;
        }
    }
}
